<!DOCTYPE html>
<html lang="zh-cn">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>获取页面元素</title>
    <style>
        .site_demo {
            list-style: none;
        }
    </style>
</head>

<body>
    <h1 id="title">俊男靓女</h1>
    <ul>
        <li class="site_demo">李昊哲</li>
        <li class="site_demo">刘晓兰</li>
        <li class="site_demo">phoenix</li>
        <li class="site_demo">小兰兰</li>
    </ul>
</body>

</html>
<script>
    // let title = window.document.querySelector('h1');
    // querySelector 返回集合对象中第一个元素
    // let title = window.document.querySelector('.site_demo');
    let title = window.document.querySelector('#title');
    window.console.log('标题--->' + title.innerText);
    // 获取元素对象的集合 注意页面获取的元素存储在一个伪数组中
    let lis = window.document.querySelectorAll('.site_demo');
    // window.console.log(lis);
    // window.console.dir(lis);
    for (let index = 0; index < lis.length; index++) {
        // 获取每一个li元素
        const element = lis[index];
        window.console.log(element.innerText);
    }
</script>